import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

class Entry {
    Integer key;
    Integer value;

    public Entry(Integer key, Integer value) {
        this.key = key;
        this.value = value;
    }
}

public class Handler {
    public static void main(String[] args) throws Exception {
        String path = "/Users/bytedance/Desktop/discover.txt";
        FileReader in = new FileReader(path);
        BufferedReader buffer = new BufferedReader(in);
        String line;
        List<Entry> list = new LinkedList<>();
        while ((line = buffer.readLine()) != null) {
            String[] split = line.trim().split("\\s+");
            //us级别的phi，要聚合到ms
            int phi = Integer.parseInt(split[0]);
            int delay = Integer.parseInt(split[1]);
            //146ms - 450ms
            if(phi >= 146000 && phi < 451000){
                list.add(new Entry(phi,delay));
            }
        }
        Collections.sort(list,(e1,e2) -> e1.key - e2.key);
        StringBuffer sb = new StringBuffer();
        //按照顺序存储
        for (Entry entry : list) {
            sb.append(entry.key).append("  ").append(entry.value).append("\r\n");
        }

        path = "/Users/bytedance/Desktop/phi.txt";
        FileWriter out = new FileWriter(path);
        BufferedWriter writer = new BufferedWriter(out);
        writer.write(sb.toString());
        writer.flush();
        writer.close();
        System.out.println(list.size());
    }
}
